package com.qeado.baike.service.implement;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qeado.baike.dao.BaikeDao;
import com.qeado.baike.model.Baike;
import com.qeado.baike.model.BaikeRef;
import com.qeado.baike.service.BaikeService;
import com.qeado.util.FileUpload;
import com.qeado.util.PageHelper;
@Service
public class BaikeServiceImplement implements BaikeService {

	@Autowired
	private BaikeDao baikeDao;
	
	public Baike queryById(String id) {
		return baikeDao.queryById(id);
	}

	public boolean insertBaike(BaikeRef baikeRef) {
		// TODO Auto-generated method stub
		return false;
	}

	public Baike queryByWord(String baikeWord) {
		return baikeDao.queryByWord(baikeWord);
	}

	public boolean createBaike(Baike baike) {
		baike.setId(UUID.randomUUID().toString());
		return baikeDao.createBaike(baike);
	}
	
	public boolean createBaike(Baike baike , FileUpload fileUpload) {
		if( fileUpload == null){
			baike.setFileName("default/default.gif");
			return createBaike(baike);
		}
		else {
			fileUpload.upload();
			baike.setFileName(fileUpload.getImageFileName());
			return createBaike(baike);
		}
	}

	public PageHelper listByKey(int pageNum, int pageSize, String key,
			String orderBy, String asc)  throws Exception{
		key = key.trim();
		key = "%" + key + "%";
		return baikeDao.listByKey(pageNum, pageSize, key, orderBy, asc );
	}

	public PageHelper listBySort(int pageNum, int pageSize, String typeCode,
			String orderBy, String asc)  throws Exception{
		return baikeDao.listBySort(pageNum, pageSize, typeCode, orderBy, asc);
	}

	public PageHelper listAll(int pageNum, int pageSize, String orderBy,
			String asc) throws Exception {
		return baikeDao.listAll(pageNum, pageSize, orderBy, asc);
	}

}
